package com.hk.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hk.mapper.CluesMapper;
import com.hk.model.dto.CluesAddDto;
import com.hk.model.dto.CluesPageDto;
import com.hk.model.pojo.Clues;
import com.hk.model.vo.CluesPageVo;
import com.hk.model.vo.CluesVo;
import com.hk.service.CluesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class CluesServiceImpl extends ServiceImpl<CluesMapper, Clues> implements CluesService {
    @Autowired
private CluesMapper cluesMapper;
    @Override
    public CluesPageVo pageList(CluesPageDto dto) {
        return getPageVo(dto,cluesMapper.listSelect(dto));
    }

    @Override
    public CluesPageVo pagePoor(CluesPageDto dto) {
        return getPageVo(dto,cluesMapper.poorSelect(dto));
    }

    @Override
    public void addClues(CluesAddDto dto) {
        //往线索表添加数据
        Clues clues=new Clues();
        BeanUtils.copyProperties(dto,clues);
        cluesMapper.insert(clues);
        //往客户表添加数据

    }


    public CluesPageVo getPageVo( CluesPageDto dto, List<CluesVo> list){
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<CluesVo> page = (Page<CluesVo>)list;
        return new CluesPageVo(200,"查询成功", null,  page.getResult(), (int) page.getTotal());
    }
}
